import java.util.Scanner;

class CircularQueue {
    private int[] queue;
    private int front;
    private int rear;
    private int size;       //元素数量
    private int longth;     //长度

    public CircularQueue(int capacity) {
        this.longth = capacity;
        this.queue = new int[capacity];
        this.front = 0;
        this.rear = -1;
        this.size = 0;
    }

    // 判断队列是否已满
    public boolean isFull() {
        return size == longth;
    }

    // 判断队列是否为空
    public boolean isEmpty() {
        return size == 0;
    }

    public void enqueue(int item) {
        if (isFull()) {
            System.out.println("Queue is full");
            return;
        }
        rear = (rear + 1) % longth;
        queue[rear] = item;
        size++;
    }

    public int dequeue() {
        if (isEmpty()) {
            System.out.println("Queue is empty");
            return -1;
        }
        int item = queue[front];
        front = (front + 1) % longth;
        size--;
        return item;
    }

    public int peek() {
        if (isEmpty()) {
            System.out.println("Queue is empty");
            return -1;
        }
        return queue[front];
    }
}

public class SanJiao {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入杨辉三角的行数：");
        int n = scanner.nextInt();
        scanner.close();

        CircularQueue queue = new CircularQueue(n + 1);
        queue.enqueue(1);

        for (int i = 0; i < n; i++) {
            // 打印前面的空格
            for (int j = 0; j < n - i - 1; j++) {
                System.out.print("   ");
            }

            int prev = 0;
            for (int j = 0; j <= i; j++) {
                int current = queue.dequeue();
                System.out.printf("%6d", current);
                queue.enqueue(prev + current);
                prev = current;
            }
            queue.enqueue(1);
            System.out.println();
        }
    }
}